package by.alex.dzeshko.lastfmsimple.content.provider;

import org.json.JSONException;
import org.json.JSONObject;

import by.alex.dzeshko.lastfmsimple.bo.ArtistModel;
import by.alex.dzeshko.lastfmsimple.content.Contract;
import by.alex.dzeshko.lastfmsimple.content.provider.common.CommonProvider;
import by.alex.dzeshko.lastfmsimple.utils.Md5;

import android.content.ContentValues;
import android.net.Uri;
import android.text.TextUtils;

public class ArtistsProvider extends CommonProvider {

	@Override
	protected String getOrderBy() {
		return null;
	}

	@Override
	protected String getTableName() {
		return Contract.ArtistsColumns.TABLE_NAME;
	}

	@Override
	protected String getContentType() {
		return Contract.ArtistsColumns.CONTENT_TYPE;
	}

	@Override
	protected Uri getContentURI() {
		return Contract.ArtistsColumns.CONTENT_URI;
	}

	@Override
	protected String[] getColumns() {
		return Contract.ArtistsColumns.COLUMNS;
	}

	@Override
	protected ContentValues getContentValues(JSONObject jsonObject)
			throws JSONException {
		ContentValues values = new ContentValues();
		ArtistModel artist = new ArtistModel(jsonObject);
		String mbid = artist.getMbid();
		String name = artist.getName();
		if(TextUtils.isEmpty(mbid)){
			mbid = Md5.convert(name);
		}
		values.put(Contract.ArtistsColumns.MBID, mbid);
		values.put(Contract.ArtistsColumns.NAME, name);
		values.put(Contract.ArtistsColumns.SUMMARY, artist.getSummary());
		values.put(Contract.ArtistsColumns.IMAGE_SMALL, artist.getImage(0));
		values.put(Contract.ArtistsColumns.IMAGE_MEDIUM, artist.getImage(1));
		values.put(Contract.ArtistsColumns.IMAGE_LARGE, artist.getImage(2));
		values.put(Contract.ArtistsColumns.IMAGE_XLARGE, artist.getImage(3));
		return values;
	}

}
